
async function getStudentList() {
    const res = await axios({
        url: '/student/list',
    })
    const studentData = res.data.data;
    // console.log(studentData);
    const nameList = studentData.map(item => item.name)
    const salaryList = studentData.map(item => item.salary)
    const trueSalaryList = studentData.map(item => item.truesalary)

    const provinceList = studentData.map(item => item.province)
    console.log(provinceList);

    let provinceData = [];
    provinceList.forEach(item => {
        // console.log(item);
        //  1、判断 item 对应省份数据 有没有在 provinceData 中定义过
        const index = provinceData.findIndex((v) => v.name === item);
        //  2、没有定义过 - 给 provinceData 添加一个新的元素  {name:item,value:1}
        if (index === -1) {
            provinceData.push({ value: 1, name: item });
        } else {
            //  3、定义过 - 找到 item 对应 数据在数组的哪个位置 provinceData[index].value++
            provinceData[index].value++;
        }
    });
    console.log(provinceData);
    /*
    data: [
        { value: 30, name: 'rose 1' },
        { value: 28, name: 'rose 2' },
        { value: 26, name: 'rose 3' },
        { value: 24, name: 'rose 4' },
        { value: 22, name: 'rose 5' },
        { value: 20, name: 'rose 6' },
        { value: 18, name: 'rose 7' },
        { value: 16, name: 'rose 8' }
    ]
    */

    // 薪资曲线
    const chartLine = document.querySelector('.line');
    const myChartLine = echarts.init(chartLine);
    const optionLine = {
        title: {
            text: '薪资情况展示'
        },
        legend: {},
        xAxis: {
            type: 'category',
            boundaryGap: false,
            data: nameList
        },
        yAxis: {
            type: 'value',
            axisLabel: {
                formatter: '{value}'
            }
        },
        series: [
            {
                name: '期望薪资',
                type: 'line',
                smooth: true,
                data: salaryList,
                color: 'rgb(238, 102, 102)',
                symbol: "none",
            },
            {
                name: '实际薪资',
                type: 'line',
                smooth: true,
                data: trueSalaryList,
                color: 'rgb(84, 112, 198)',
                symbol: "none",
            }
        ],
        dataZoom: [
            {},
            {
                type: 'inside'
            }
        ],
    };
    myChartLine.setOption(optionLine);

    // 籍贯 南丁格尔图
    const chartPie = document.querySelector('.pie');
    const myChartPie = echarts.init(chartPie);
    const optionPie = {
        title: {
            text: '籍贯',
            // left: 'center'
        },
        tooltip: {
            trigger: 'item',
            formatter: '{a} <br/>{b} : {c} ({d}%)'
        },
        series: [
            {
              name: '省份',
              type: 'pie',
              radius: [15, 150],
              center: ['50%', '50%'],
              roseType: 'area',
              itemStyle: {
                borderRadius: 8
              },
              data: provinceData
            }
          ]
    };
    myChartPie.setOption(optionPie);
}

getStudentList()
